package com.scuec.groupfive.Controller;

import com.scuec.groupfive.entity.PostComment;
import com.scuec.groupfive.service.PostCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/post-comment")
public class PostCommentController {
    @Autowired
    private PostCommentService postCommentService;

    @GetMapping("/total-count")
    public int getTotalCommentCount() {
        return postCommentService.getTotalCommentCount();
    }

    @GetMapping("/count/{postId}")
    public int getCommentCountByPostId(@PathVariable Long postId) {
        return postCommentService.getCommentCountByPostId(postId);
    }

    @GetMapping("/count-by-date")
    public int getCommentCountByDateRange(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        return postCommentService.getCommentCountByDateRange(startDate, endDate);
    }

    @GetMapping("/list/{postId}")
    public List<PostComment> getCommentsByPostId(
            @PathVariable Long postId,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        return postCommentService.getCommentsByPostId(postId, page, size);
    }

    @DeleteMapping("/{commentId}")
    public boolean deleteComment(@PathVariable Long commentId) {
        return postCommentService.deleteComment(commentId);
    }
    @PutMapping("/restore/{commentId}") // 恢复评论接口
    public boolean restoreComment(@PathVariable Long commentId) {
        return postCommentService.restoreComment(commentId);
    }
}